import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/**
 * 路由路径
 */
//主页
import home from '@/components/page/user/home/Index';
//用户中心
import center from '@/components/page/user/center/Index';
//收货地址
import address from '@/components/page/user/center/Address';
//发布物品
import newProduct from '@/components/page/user/product/NewProduct';
//商品详情
import product from '@/components/page/user/product/Index';

/* 后台管理*/
//商品管理
import goods from '@/components/page/system/good/GoodList';
//用户管理
import users from '@/components/page/system/user/UserList';

const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path:'/',
        component: () => import('../components/userCom/Home.vue'),
        meta:{
            title:'用户'
        },
        children:[
            {
                path:'/home',
                component: home,
                meta: {
                    title: '主页'
                }
            },
            {
                path:'/center',
                component: center,
                meta: {
                    title: '用户中心'
                }
            },
            {
                path:'/address',
                component: address,
                meta: {
                    title: '收货地址'
                }
            },
            {
                path:'/newProduct',
                component: newProduct,
                meta: {
                    title: '发布物品'
                }
            },
            {
                path:'/product',
                component: product,
                meta: {
                    title: '商品详情'
                }
            }
        ]
    },
    {
        path:'/system',
        component: () => import('../components/systemCom/Home.vue'),
        meta:{
            title:'管理员'
        },
        children:[
            {
                path:'/system/goods',
                component: goods,
                meta:{
                    title:'商品管理'
                }
            },
            {
                path:'/system/users',
                component: users,
                meta:{
                    title:'用户管理'
                }
            },
        ]
    },
    {
        path: '/login',
        component: () => import('../components/page/Login.vue'),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/signIn',
        component: () => import('../components/page/SignIn.vue'),
        meta:{
            title:'注册'
        }
    },
    {
        path: '*',
        component: () => import('../components/page/404.vue')
    }
];

const router = new Router({
    mode: 'history',
    routes
})

router.beforeEach((to, from, next) => {
    if(to.meta.title){
        document.title = to.meta.title
    }
    next()
})
export default router;